<?php

class AdminModule extends CWebModule {

    public function init() {
        // this method is called when the module is being created
        // you may place code here to customize the module or the application
        // import the module-level models and components
        $this->setImport(array(
            'admin.models.*',
            'admin.components.*',
        ));
        $client = Yii::app()->clientScript;
        $client->registerCoreScript('jquery');
        $client->registerCoreScript('yii');
        $client->registerCoreScript('jquery.ui');
    }

    public function beforeControllerAction($controller, $action) {
        if (parent::beforeControllerAction($controller, $action)) {
            if ( !Yii::app()->cookies->admin) {
                echo Yii::app()->cookies->admin;
                if ($action->getId() != "login") {
                   Yii::app()->request->redirect(CController::createUrl('/' . $this->getId() . "/default/login"));
                }
            }
            return true;
        }
        else
            return false;
    }

}